package com.example.administrator.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.bumptech.glide.Glide;

import java.util.LinkedHashMap;

import cn.jzvd.JZDataSource;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

public class RtmpActivity extends AppCompatActivity {

    WebView mWebView;
    MyRtmpPlayer jzvdStd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rtmp);
        mWebView = findViewById(R.id.webview);
        jzvdStd = findViewById(R.id.videoplayer);


        initWebView();
        initPlayer();


    }

    private void initPlayer() {
        JzvdStd.SAVE_PROGRESS = false;
        JZMediaIjkplayer a = new JZMediaIjkplayer();

        JzvdStd.setMediaInterface(a);
        jzvdStd.setUp("rtmp://pili-publish.sou001.com/kuailai/testtest","测试",Jzvd.SCREEN_WINDOW_NORMAL);
        jzvdStd.startButton.performClick();
        //Glide.with(this).load("http://192.168.0.110/videojs/oceans.png").into(jzvdStd.thumbImageView);
    }

    private void initWebView() {
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setSupportZoom(false);
        webSettings.setAllowFileAccess(true);
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.addJavascriptInterface(new AndroidtoJs(), "Share");
        mWebView.loadUrl("http://dollv2.deerlive.com/www/index.html");
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }
    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.releaseAllVideos();
    }

    public class AndroidtoJs extends Object {
        @JavascriptInterface
        public void code() {

        }
    }
}
